// pages/index/shops/shops.js
import {
  Toast
} from 'wuss-weapp';
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabbar:{},
    type:"D0041_4",
    index:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    app.editTabbar();
    this.setData({
      theme: app.globalData.theme
    });
    this.shopsLoad();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    app.globalData.pageNumber = 1;
    app.globalData.pageTotalNumber = 0;
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    app.globalData.pageNumber = 1;
    this.setData({
      result: []
    });
    this.shopsLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    app.globalData.pageNumber++;
    this.setData({
      mpLoadingShow: true,
      mpLoadingTips: "加载中..."
    });
    if (app.globalData.pageNumber <= app.globalData.pageTotalNumber) {
      this.shopsLoad();
    } else {
      setTimeout(() => {
        this.setData({
          mpLoadingTips: "暂无数据"
        });
      }, 500);
      setTimeout(() => {
        this.setData({
          mpLoadingShow: false
        });
      }, 1000);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  /**
   * 加载数据
   */
  shopsLoad: function() {
    app.wxGetRequest("/wechart/microofficial/getNoRecommendRoundList", {
      area_code: app.globalData.parentAreaCode,
      type: this.data.type,
      // pageNumber: app.globalData.pageNumber,
      // pageSize: app.globalData.pageSize,
      //people_id:app.globalData.userInfo["people_id"]
    }).then(result => {
      let data = result.data.data;
      this.setData({
        result: data,
        noData: data.length == 0 ? true : false,
        mpLoadingShow: false
      });
      // app.globalData.pageTotalNumber = pageTotalNumber;
    });
  },
  /**
   * 商家详情
   */
  indexShopDetail: function(e) {
    let id = e.currentTarget.dataset.id;
    let phone = e.currentTarget.dataset.phone;
    let type = e.currentTarget.dataset.type;
    if(type == "D0041_15" || type == "D0041_16"){
      wx.navigateTo({
        url: '/pages/index/service_more/consultation/consultation?id=' + id
      })
      return
    }
    wx.navigateTo({
      url: '/pages/index/life_service/life_service_detail/life_service_detail?id=' + id + "&phone=" + phone,
    })
  },
  changeShop: function(e) {
    let index = e.currentTarget.dataset.index;
    let type = e.currentTarget.dataset.type;
    this.setData({
      index: index,
      type: type,
      result:[]
    });
    wx.showLoading({
      title: '加载中...',
    })
    this.shopsLoad();
  }
})